Skip to content

Add tests coverage for the transaction balancing with withdrawal#1186

Merged
carbolymer merged 1 commit into
masterfrom
mgalazyn/test/balancing-withdrawal-tx
Apr 24, 2026
Merged

Add tests coverage for the transaction balancing with withdrawal#1186
carbolymer merged 1 commit into
masterfrom
mgalazyn/test/balancing-withdrawal-tx

Conversation

@carbolymer
Copy link
Copy Markdown
Contributor

@carbolymer carbolymer commented Apr 20, 2026

Context

makeTransactionBodyAutoBalance now returns TxBodyErrorBalanceNegative when the transaction balance is negative, instead of crashing with an Illegal Value in TxOut runtime error from toCompact on a negative Coin.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff
  • Changelog fragment added in .changes/

Copilot AI review requested due to automatic review settings April 20, 2026 12:05
@carbolymer carbolymer self-assigned this Apr 20, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds regression coverage around fee balancing for withdrawal-funded transactions, and hardens the experimental auto-balance path to avoid an unrecoverable ledger TxOut construction failure on negative balances.

Changes:

  • Add two new calcMinFeeRecursive Hedgehog properties for withdrawal-funded balancing success/failure cases.
  • Add generators for withdrawal-funded transactions (including a tiny-input variant).
  • Add an early non-negative balance guard in makeTransactionBodyAutoBalance before constructing the initial change TxOut.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
cardano-api/test/cardano-api-test/Test/Cardano/Api/Experimental/Fee.hs Adds new generators + properties to cover withdrawal-funded balancing scenarios.
cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Fee.hs Adds a pre-mkBasicTxOut balance check to avoid an irrecoverable crash on negative values.

Comment thread cardano-api/test/cardano-api-test/Test/Cardano/Api/Experimental/Fee.hs Outdated
Comment thread cardano-api/test/cardano-api-test/Test/Cardano/Api/Experimental/Fee.hs Outdated
Comment thread cardano-api/test/cardano-api-test/Test/Cardano/Api/Experimental/Fee.hs Outdated
@carbolymer carbolymer force-pushed the mgalazyn/test/balancing-withdrawal-tx branch 6 times, most recently from 4c33c46 to f283dd6 Compare April 22, 2026 18:38
@carbolymer carbolymer requested a review from Copilot April 22, 2026 18:38
@carbolymer carbolymer force-pushed the mgalazyn/test/balancing-withdrawal-tx branch from f283dd6 to 6636b2e Compare April 22, 2026 18:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Copy link
Copy Markdown
Contributor

@palas palas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It all looks correct and I've verified that:

  • "withdrawal-funded transaction (output > input) succeeds" fails without withdrawal
  • "underfunded transaction fails with TxBodyErrorBalanceNegative" fails without the patch in cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Fee.hs

Maybe worth adding the new tests to the change-log too?

@carbolymer carbolymer force-pushed the mgalazyn/test/balancing-withdrawal-tx branch from 6636b2e to 3b06c0c Compare April 24, 2026 08:26
@carbolymer carbolymer enabled auto-merge April 24, 2026 08:27
@carbolymer carbolymer added this pull request to the merge queue Apr 24, 2026
Merged via the queue into master with commit 12b4591 Apr 24, 2026
33 checks passed
@carbolymer carbolymer deleted the mgalazyn/test/balancing-withdrawal-tx branch April 24, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants